package com.liujit.bms.admin.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liujit.bms.admin.domain.model.BlogMemberFeedback;
import com.liujit.bms.admin.domain.params.BlogMemberFeedbackParams;
import com.liujit.bms.admin.domain.query.BlogMemberFeedbackQuery;
import com.liujit.bms.admin.domain.result.BlogMemberFeedbackResult;
import com.liujit.bms.admin.mapper.BlogMemberFeedbackMapper;
import com.liujit.bms.admin.service.BlogMemberFeedbackService;
import com.liujit.common.domain.params.BaseParams;
import com.liujit.common.domain.result.PageBean;
import com.liujit.common.exception.DataNotFoundException;
import com.liujit.common.utils.DozerConvertor;
import com.liujit.common.utils.Pagination;
import org.springframework.stereotype.Service;

/**
 * @Description 博客会员反馈Service实现类
 * @Author liujun
 * @Date 2021-07-19 11:19:24
 */
@Service
public class BlogMemberFeedbackServiceImpl extends ServiceImpl<BlogMemberFeedbackMapper, BlogMemberFeedback>
        implements BlogMemberFeedbackService {

    @Override
    public PageBean<BlogMemberFeedbackResult> getPage(BlogMemberFeedbackQuery query) {
        Page<BlogMemberFeedbackResult> page = Pagination.page(query);
        IPage<BlogMemberFeedbackResult> iPage = super.baseMapper.selPage(page, query);
        return PageBean.page(iPage);
    }

    @Override
    public Boolean reply(BlogMemberFeedbackParams params) {
        BlogMemberFeedback entity = DozerConvertor.convertor(params, BlogMemberFeedback.class);
        BlogMemberFeedback blogMemberFeedback = super.getById(params.getId());
        if (blogMemberFeedback == null) {
            throw new DataNotFoundException();
        }
        return super.updateById(entity);
    }

    @Override
    public BlogMemberFeedbackResult get(Long id) {
        BlogMemberFeedback blogMemberFeedback = super.getById(id);
        if (blogMemberFeedback == null) {
            throw new DataNotFoundException();
        }
        return DozerConvertor.convertor(blogMemberFeedback, BlogMemberFeedbackResult.class);
    }

    @Override
    public BlogMemberFeedbackResult getDetail(Long id) {
        BlogMemberFeedbackResult result = super.baseMapper.selById(id);
        if (result == null) {
            throw new DataNotFoundException();
        }
        return result;
    }

    @Override
    public Boolean del(BaseParams params) {
        BlogMemberFeedback blogMemberFeedback = super.getById(params.getId());
        if (blogMemberFeedback == null) {
            throw new DataNotFoundException();
        }
        return super.removeById(params.getId());
    }
}
